<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Constructs a new, empty rollup network layout. Layouts are not typically
<span class='line'>  3</span>  * constructed directly; instead, they are added to an existing panel via
<span class='line'>  4</span>  * {@link pv.Mark#add}.
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * @class Implements a network visualization using a node-link diagram where
<span class='line'>  7</span>  * nodes are rolled up along two dimensions. This implementation is based on the
<span class='line'>  8</span>  * "PivotGraph" designed by Martin Wattenberg:
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * &lt;blockquote>The method is designed for graphs that are "multivariate", i.e.,
<span class='line'> 11</span>  * where each node is associated with several attributes. Unlike visualizations
<span class='line'> 12</span>  * which emphasize global graph topology, PivotGraph uses a simple grid-based
<span class='line'> 13</span>  * approach to focus on the relationship between node attributes &amp;
<span class='line'> 14</span>  * connections.&lt;/blockquote>
<span class='line'> 15</span>  *
<span class='line'> 16</span>  * This layout requires two psuedo-properties to be specified, which assign node
<span class='line'> 17</span>  * positions along the two dimensions {@link #x} and {@link #y}, corresponding
<span class='line'> 18</span>  * to the left and top properties, respectively. Typically, these functions are
<span class='line'> 19</span>  * specified using an {@link pv.Scale.ordinal}. Nodes that share the same
<span class='line'> 20</span>  * position in &lt;i>x&lt;/i> and &lt;i>y&lt;/i> are "rolled up" into a meta-node, and
<span class='line'> 21</span>  * similarly links are aggregated between meta-nodes. For example, to construct
<span class='line'> 22</span>  * a rollup to analyze links by gender and affiliation, first define two ordinal
<span class='line'> 23</span>  * scales:
<span class='line'> 24</span>  *
<span class='line'> 25</span>  * &lt;pre>var x = pv.Scale.ordinal(nodes, function(d) d.gender).split(0, w),
<span class='line'> 26</span>  *     y = pv.Scale.ordinal(nodes, function(d) d.aff).split(0, h);&lt;/pre>
<span class='line'> 27</span>  *
<span class='line'> 28</span>  * Next, define the position psuedo-properties:
<span class='line'> 29</span>  *
<span class='line'> 30</span>  * &lt;pre>    .x(function(d) x(d.gender))
<span class='line'> 31</span>  *     .y(function(d) y(d.aff))&lt;/pre>
<span class='line'> 32</span>  *
<span class='line'> 33</span>  * Linear and other quantitative scales can alternatively be used to position
<span class='line'> 34</span>  * the nodes along either dimension. Note, however, that the rollup requires
<span class='line'> 35</span>  * that the positions match exactly, and thus ordinal scales are recommended to
<span class='line'> 36</span>  * avoid precision errors.
<span class='line'> 37</span>  *
<span class='line'> 38</span>  * &lt;p>Note that because this layout provides a visualization of the rolled up
<span class='line'> 39</span>  * graph, the data properties for the mark prototypes (&lt;tt>node&lt;/tt>,
<span class='line'> 40</span>  * &lt;tt>link&lt;/tt> and &lt;tt>label&lt;/tt>) are different from most other network
<span class='line'> 41</span>  * layouts: they reference the rolled-up nodes and links, rather than the nodes
<span class='line'> 42</span>  * and links of the full network. The underlying nodes and links for each
<span class='line'> 43</span>  * rolled-up node and link can be accessed via the &lt;tt>nodes&lt;/tt> and
<span class='line'> 44</span>  * &lt;tt>links&lt;/tt> attributes, respectively. The aggregated link values for
<span class='line'> 45</span>  * rolled-up links can similarly be accessed via the &lt;tt>linkValue&lt;/tt>
<span class='line'> 46</span>  * attribute.
<span class='line'> 47</span>  *
<span class='line'> 48</span>  * &lt;p>For undirected networks, links are duplicated in both directions. For
<span class='line'> 49</span>  * directed networks, use &lt;tt>directed(true)&lt;/tt>. The graph is assumed to be
<span class='line'> 50</span>  * undirected by default.
<span class='line'> 51</span>  *
<span class='line'> 52</span>  * @extends pv.Layout.Network
<span class='line'> 53</span>  * @see &lt;a href="http://www.research.ibm.com/visual/papers/pivotgraph.pdf"
<span class='line'> 54</span>  * >"Visual Exploration of Multivariate Graphs"&lt;/a> by M. Wattenberg, CHI 2006.
<span class='line'> 55</span>  */</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="NAME">pv.Layout.Rollup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">  </span><span class="NAME">pv.Layout.Network.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">that</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">      </span><span class="NAME">nodes</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached rollup nodes</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">      </span><span class="NAME">links</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached rollup links</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">      </span><span class="NAME">buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">that.buildImplied</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> 
<span class='line'> 63</span> </span><span class="WHIT">  </span><span class="COMM">/** @private Cache layout state to optimize properties. */</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">  </span><span class="NAME">this.buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">    </span><span class="NAME">buildImplied.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">    </span><span class="NAME">nodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.$rollup.nodes</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">    </span><span class="NAME">links</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.$rollup.links</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> 
<span class='line'> 70</span> </span><span class="WHIT">  </span><span class="COMM">/* Render rollup nodes. */</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">  </span><span class="NAME">this.node</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">size</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">d</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">d.nodes.length</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NUMB">20</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 74</span> 
<span class='line'> 75</span> </span><span class="WHIT">  </span><span class="COMM">/* Render rollup links. */</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">  </span><span class="NAME">this.link</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">interpolate</span><span class="PUNC">(</span><span class="STRN">"polar"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">eccentricity</span><span class="PUNC">(</span><span class="PUNC">.</span><span class="NUMB">8</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> 
<span class='line'> 80</span> </span><span class="WHIT">  </span><span class="NAME">this.link.add</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">that.add</span><span class="PUNC">(</span><span class="NAME">pv.Panel</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">        </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">add</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">        </span><span class="PUNC">.</span><span class="NAME">extend</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> 
<span class='line'> 88</span> </span><span class="NAME">pv.Layout.Rollup.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.extend</span><span class="PUNC">(</span><span class="NAME">pv.Layout.Network</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">    </span><span class="PUNC">.</span><span class="NAME">property</span><span class="PUNC">(</span><span class="STRN">"directed"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">Boolean</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 90</span> 
<span class='line'> 91</span> </span><span class="COMM">/**
<span class='line'> 92</span>  * Whether the underlying network is directed. By default, the graph is assumed
<span class='line'> 93</span>  * to be undirected, and links are rendered in both directions. If the network
<span class='line'> 94</span>  * is directed, then forward links are drawn above the diagonal, while reverse
<span class='line'> 95</span>  * links are drawn below.
<span class='line'> 96</span>  *
<span class='line'> 97</span>  * @type boolean
<span class='line'> 98</span>  * @name pv.Layout.Rollup.prototype.directed
<span class='line'> 99</span>  */</span><span class="WHIT">
<span class='line'>100</span> 
<span class='line'>101</span> </span><span class="COMM">/**
<span class='line'>102</span>  * Specifies the &lt;i>x&lt;/i>-position function used to rollup nodes. The rolled up
<span class='line'>103</span>  * nodes are positioned horizontally using the return values from the given
<span class='line'>104</span>  * function. Typically the function is specified as an ordinal scale. For
<span class='line'>105</span>  * single-dimension rollups, a constant value can be specified.
<span class='line'>106</span>  *
<span class='line'>107</span>  * @param {function} f the &lt;i>x&lt;/i>-position function.
<span class='line'>108</span>  * @returns {pv.Layout.Rollup} this.
<span class='line'>109</span>  * @see pv.Scale.ordinal
<span class='line'>110</span>  */</span><span class="WHIT">
<span class='line'>111</span> </span><span class="NAME">pv.Layout.Rollup.prototype.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">  </span><span class="NAME">this.$x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.functor</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>114</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>115</span> 
<span class='line'>116</span> </span><span class="COMM">/**
<span class='line'>117</span>  * Specifies the &lt;i>y&lt;/i>-position function used to rollup nodes. The rolled up
<span class='line'>118</span>  * nodes are positioned vertically using the return values from the given
<span class='line'>119</span>  * function. Typically the function is specified as an ordinal scale. For
<span class='line'>120</span>  * single-dimension rollups, a constant value can be specified.
<span class='line'>121</span>  *
<span class='line'>122</span>  * @param {function} f the &lt;i>y&lt;/i>-position function.
<span class='line'>123</span>  * @returns {pv.Layout.Rollup} this.
<span class='line'>124</span>  * @see pv.Scale.ordinal
<span class='line'>125</span>  */</span><span class="WHIT">
<span class='line'>126</span> </span><span class="NAME">pv.Layout.Rollup.prototype.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">  </span><span class="NAME">this.$y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.functor</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> 
<span class='line'>131</span> </span><span class="COMM">/** @private */</span><span class="WHIT">
<span class='line'>132</span> </span><span class="NAME">pv.Layout.Rollup.prototype.buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">pv.Layout.Network.prototype.buildImplied.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span> 
<span class='line'>135</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.nodes</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">      </span><span class="NAME">links</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.links</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">      </span><span class="NAME">directed</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.directed</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">      </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nodes.length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">      </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">      </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">      </span><span class="NAME">rnindex</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">      </span><span class="NAME">rnodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">      </span><span class="NAME">rlinks</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> 
<span class='line'>145</span> </span><span class="WHIT">  </span><span class="COMM">/** @private */</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">  </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">id</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">","</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>149</span> 
<span class='line'>150</span> </span><span class="WHIT">  </span><span class="COMM">/* Iterate over the data, evaluating the x and y functions. */</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">stack</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.Mark.stack</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="NAME">parent</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">  </span><span class="NAME">stack.unshift</span><span class="PUNC">(</span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT">    </span><span class="NAME">o.index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT">    </span><span class="NAME">stack</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">    </span><span class="NAME">x</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.$x.apply</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">stack</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">    </span><span class="NAME">y</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.$y.apply</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">stack</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">  </span><span class="NAME">stack.shift</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>160</span> 
<span class='line'>161</span> </span><span class="WHIT">  </span><span class="COMM">/* Compute rollup nodes. */</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">nodes.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nodeId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">id</span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">        </span><span class="NAME">rn</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rnodes</span><span class="PUNC">[</span><span class="NAME">nodeId</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">rn</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">      </span><span class="NAME">rn</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rnodes</span><span class="PUNC">[</span><span class="NAME">nodeId</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.extend</span><span class="PUNC">(</span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">      </span><span class="NAME">rn.index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rnindex</span><span class="PUNC">++</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">      </span><span class="NAME">rn.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">      </span><span class="NAME">rn.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">      </span><span class="NAME">rn.nodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">    </span><span class="NAME">rn.nodes.push</span><span class="PUNC">(</span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>174</span> 
<span class='line'>175</span> </span><span class="WHIT">  </span><span class="COMM">/* Compute rollup links. */</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">links.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">sourceNode</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">        </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">targetNode</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">        </span><span class="NAME">rsource</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rnodes</span><span class="PUNC">[</span><span class="NAME">id</span><span class="PUNC">(</span><span class="NAME">source.index</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">        </span><span class="NAME">rtarget</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rnodes</span><span class="PUNC">[</span><span class="NAME">id</span><span class="PUNC">(</span><span class="NAME">target.index</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT">        </span><span class="NAME">reverse</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">directed</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">rsource.index</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">rtarget.index</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT">        </span><span class="NAME">linkId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">reverse</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT">            </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">rtarget.index</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">","</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">rsource.index</span><span class="WHIT">
<span class='line'>184</span> </span><span class="WHIT">            </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">rsource.index</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">","</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">rtarget.index</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>185</span> </span><span class="WHIT">        </span><span class="NAME">rl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rlinks</span><span class="PUNC">[</span><span class="NAME">linkId</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">rl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>187</span> </span><span class="WHIT">      </span><span class="NAME">rl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rlinks</span><span class="PUNC">[</span><span class="NAME">linkId</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>188</span> </span><span class="WHIT">        </span><span class="NAME">sourceNode</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">rsource</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">        </span><span class="NAME">targetNode</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">rtarget</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">        </span><span class="NAME">linkValue</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">        </span><span class="NAME">links</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">    </span><span class="NAME">rl.links.push</span><span class="PUNC">(</span><span class="NAME">links</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">    </span><span class="NAME">rl.linkValue</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">linkValue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>197</span> 
<span class='line'>198</span> </span><span class="WHIT">  </span><span class="COMM">/* Export the rolled up nodes and links to the scene. */</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT">  </span><span class="NAME">s.$rollup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT">    </span><span class="NAME">nodes</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">pv.values</span><span class="PUNC">(</span><span class="NAME">rnodes</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>201</span> </span><span class="WHIT">    </span><span class="NAME">links</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">pv.values</span><span class="PUNC">(</span><span class="NAME">rlinks</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>202</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>204</span> </span></pre></body></html>